#include <math.h>
#define INIT_SIZE 2



template <typename T>
class CVectorIterator
{
public:
	CVectorIterator(){}
	CVectorIterator(T* pBegin):ptr(pBegin){}
	T& operator *() const{return* ptr;}

	CVectorIterator& operator++()
	{
		ptr++;
		return this;
	}
	CVectorIterator operator++(int)
	{
		CVectorIterator cTemp = *this;
		ptr++;
		return cTemp;
	}
	bool operator!=(T *t)
	{
		return *ptr!=*t;
	}
	T* operator=(T *t)
	{
	    ptr=t;
		return ptr;
	}
private:
	T *ptr;
};

template <typename T>
class Cvector
{
public:
	Cvector():m_iSzie(INIT_SIZE),m_iLength(0),m_iResizeCount(0)
	{
		m_pEnd = m_pBegin = (T*)malloc(sizeof(T)*INIT_SIZE);
		m_pFinish = m_pBegin + m_iSzie -1;
	};
	Cvector(T &t):m_iSzie(INIT_SIZE),m_iLength(0),m_iResizeCount(0)
	{
		m_pEnd = m_pBegin = (T*)malloc(sizeof(T)*INIT_SIZE);
		m_pFinish = m_pBegin + m_iSzie -1;
	};

	bool push_back(T t)
	{
		if (m_iLength==m_iSzie)
		{
			resize();
		}
		
		*(m_pEnd) = t;
		m_pEnd = m_pBegin + ++m_iLength;
		return true;
	}

	bool resize()
	{
		m_iSzie = size_t(pow(2.0,++m_iResizeCount)*m_iLength);
		m_pBegin = (T*)realloc(m_pBegin,m_iSzie*sizeof(T));
		m_pFinish = m_pBegin + m_iSzie -1;
		return true;
	}

	int insert(T t,int iPos)
	{
		if (m_iLength==m_iSzie)
		{
			resize();
		}
		
		memmove(m_pBegin+iPos+1,m_pBegin+iPos,sizeof(T)*(m_iSzie-iPos));
		*(m_pBegin+iPos) = t;
		m_pEnd = m_pBegin + ++m_iLength;
		return iPos;
	}

	T* begin()
	{
		return m_pBegin;
	}

	T* end()
	{
		return m_pEnd;
	}
	
	typedef T value_type;
	typedef CVectorIterator<T> iterator;

private:
	T* m_pBegin;
	T* m_pEnd;
	T* m_pFinish;
	size_t m_iSzie;
	int m_iLength;
	int m_iResizeCount;
	
};